﻿using log4net;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using Timesheet.Data.Infrastructure;
using Timesheet.Data.Repository;
using Timesheet.Domain;

namespace Timesheet.Service
{
    public class DisciplinesService : IDisciplinesService
    {
        private readonly IDisciplinesRepository _Repository;
        private readonly IUnitOfWork _UnitOfWork;
        private readonly ITeamRepository _TeamRepository;
        public ILog Logger { get; private set; }

        public DisciplinesService(ITeamRepository teamRepository,IDisciplinesRepository DisciplinesRepository,IUnitOfWork unitOfWork)
        {
            this._Repository = DisciplinesRepository;
            this._UnitOfWork = unitOfWork;
            this._TeamRepository = teamRepository;
        }


        #region IDisciplinesService Members

        public IList<Disciplines> GetDisciplines()
        {
            return this._Repository.GetAll().OrderBy(x=>x.Id).ToList();
        }

        public bool CheckExist(Disciplines entity)
        {
            throw new NotImplementedException();
        }

        public Disciplines GetByID(Int64 id)
        {
            return this._Repository.GetById(id);
        }

        public void Add(Disciplines entity)
        {
            this._Repository.Add(entity);
        }

        public void Update(Disciplines entity)
        {
            this._Repository.Update(entity);
        }

        public void Delete(Disciplines entity)
        {
            this._Repository.Delete(entity);
        }             
      
        public IList<Disciplines> GetByPrjID(long prjID)
        {
            var qTeam = this._TeamRepository.GetQuery().Where(x => x.ProjectID == prjID);
            var qDic = this._Repository.GetQuery().Where(x => qTeam.Any(t => t.DesciplineID == x.Id));
            return qDic.ToList();
        }

        #endregion
    }
}
